Euler 003

Sep 4, 2013

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

import math

def primes_in(x):
    c = [True] * x
    for i in range(2, x / 2):
        if c[i]:
            for j in range(i * i, x, i):j
                    c[j] = False
    y = []
    for i in range(2, x):
        if (c[i]):
            y.append(i)
    return y

def solve(x):
    primes = primes_in(int(math.sqrt(x)))

    y = []
    for prime in primes:
        if x % prime == 0:
            y.append(prime)
    print y

print solve(600851475143)